package com.cskaoyan.controller;

import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

/**
 * @author stone
 * @date 2022/03/24 17:31
 */
@RestController
public class HelloController {

    @RequestMapping("hello")
    public String hello(HttpServletRequest request, HttpServletResponse response) {
        //request.getParameter()
        return "success";
    }
    @RequestMapping("cookie")
    public String cookie(HttpServletRequest request) {
        Cookie[] cookies = request.getCookies();
        for (Cookie cookie : cookies) {
            System.out.println(cookie.getName() + " → " + cookie.getValue());
        }
        return "success";
    }

    @RequestMapping("session1")
    public String session1(HttpSession session) {
        session.setAttribute("songge","松哥");
        return "success";
    }

    @RequestMapping("session2")
    public String session2(HttpServletRequest request) {
        HttpSession session = request.getSession();
        Object songge = session.getAttribute("songge");
        System.out.println(songge);
        return "success";
    }
}
